package com.ctshk.app.system.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.CompanyType;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.system.dto.DispatchOrderRulePageDTO;
import com.ctshk.rpc.system.dto.DispatchOrderUserListDTO;
import com.ctshk.rpc.system.req.DispatchOrderRuleGetUserReq;
import com.ctshk.rpc.system.req.DispatchOrderRulePageReq;
import com.ctshk.rpc.system.req.DispatchOrderRuleSaveReq;
import com.ctshk.rpc.system.service.IDispatchOrderRuleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 谢诗宏
 * @since 2021-05-24
 */
@Api(value = "派单管理", tags = "派单管理")
@RestController
@RequestMapping("/dispatch/order/rule")
public class DispatchOrderRuleController extends BaseController {
    @DubboReference
    IDispatchOrderRuleService dispatchOrderRuleService;

    @ApiOperation(value = "分页查询派单规则列表", notes = "分页查询派单规则列表")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "分页查询派单规则列表", operDesc = "分页查询派单规则列表")
    @PostMapping(value = "/page")
    public Result<PageResponse<DispatchOrderRulePageDTO>> page(@RequestBody @Valid DispatchOrderRulePageReq req) {
        return dispatchOrderRuleService.page(req);
    }

    @ApiOperation(value = "保存派单规则", notes = "保存派单规则")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.ADD, operTitle = "保存派单规则", operDesc = "保存派单规则")
    @PostMapping(value = "/save")
    public Result save(@RequestBody @Valid DispatchOrderRuleSaveReq req) {
        return dispatchOrderRuleService.save(req, getCurrentUser().getId());
    }

    @ApiOperation(value = "获取公司类型", notes = "获取公司类型")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "获取公司类型", operDesc = "获取公司类型")
    @GetMapping(value = "/company/type")
    public Result getCompanyType() {
        return Result.success(CompanyType.toList());
    }

    @ApiOperation(value = "获取派单人", notes = "获取派单人")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "获取派单人", operDesc = "获取派单人")
    @PostMapping(value = "/dispatch/user")
    public Result save(@RequestBody @Valid DispatchOrderRuleGetUserReq req) {
        return dispatchOrderRuleService.getDispatchUserId(req);
    }

    @ApiOperation(value = "根据派单规则获取派单人列表", notes = "根据派单规则获取派单人列表")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "根据派单规则获取派单人列表", operDesc = "根据派单规则获取派单人列表")
    @GetMapping(value = "/dispatch/user/list/{id}")
    public Result<List<DispatchOrderUserListDTO>> getDispatchUserListById(@PathVariable("id") Long id) {
        return dispatchOrderRuleService.getDispatchUserListById(id);
    }
}
